package com.anuyun.ms.base.config;

import java.time.LocalDateTime;

import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import com.anuyun.ms.base.util.IdUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

/**
 * 自动填充策略
 * @author yufeng
 *
 */
@Component
public class MybatisMetaObjectHandler implements MetaObjectHandler  {
	/**
	 * 插入时候的填充策略
	 */
    @Override
    public void insertFill(MetaObject metaObject) {
    	this.setFieldValByName("id",IdUtil.createUUID(),metaObject);
    	this.setFieldValByName("deleted",0,metaObject);
    	this.setFieldValByName("version",0,metaObject);
        this.setFieldValByName("createTime",LocalDateTime.now(),metaObject);
        this.setFieldValByName("modifyTime",LocalDateTime.now(),metaObject);

    }

    /**
     * 更新时候的填充策略
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("modifyTime",LocalDateTime.now(),metaObject);
    }

}
